package com.ohos.carbon.slice;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
import ohos.agp.components.element.ElementScatter;

import java.util.Map;

import static com.ohos.carbon.ResourceTable.*;
import static com.ohos.carbon.slice.MainAbilitySlice.pf;

public class TextAppearanceSlice extends AbilitySlice implements Component.ClickedListener {
    private Image back_button, debug, checkbox;
    private Text text_title;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(Layout_ability_textAppearance);
        initView();

        MainAbilitySlice.all = (Map<String, Integer>) pf.getAll();
        if (MainAbilitySlice.all.size() != 0) {
            if (MainAbilitySlice.all.containsKey("Text appearance")) {
                for (Map.Entry<String, Integer> entry : MainAbilitySlice.all.entrySet()) {
                    if (entry.getKey().equals("Text appearance")) {
                        int integer = entry.getValue();
                        integer++;
                        pf.putInt("Text appearance", integer);
                        pf.flushSync();
                    }
                }
            } else {
                pf.putInt("Text appearance", 1);
                pf.flushSync();
            }
        } else {
            pf.putInt("Text appearance", 1);
            pf.flushSync();
        }
    }

    private void initView() {
        back_button = (Image) findComponentById(Id_back_button);
        back_button.setClickedListener(this);
        debug = (Image) findComponentById(Id_image1);
        debug.setClickedListener(this);
        checkbox = (Image) findComponentById(Id_image2);
        checkbox.setClickedListener(this);
        text_title = (Text) findComponentById(Id_title_text);
        text_title.setText("Text appearance");
        back_button.setImageElement(ElementScatter.getInstance(getContext()).parse(Graphic_carbon_uparrow));
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        if (component.getId() == Id_back_button) {
            onBackPressed();
        } else if (component.getId() == Id_image1) {

        } else if (component.getId() == Id_image2) {

        }
    }

    @Override
    protected void onBackPressed() {
        super.onBackPressed();
    }
}
